package com.fauks.ssm.springmvc.annotation;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

@Controller
@RequestMapping("/jump")
public class JumpController {

    @RequestMapping("/redirect")
    public ModelAndView testRedirect() {
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("name", "hello");
        modelAndView.addObject("age", 1111);
        //重定向到jsp，默认为forward转发
        //modelAndView.setViewName("redirect:/redirect.jsp");
        //重定向到另一个Action，参数依然使用get的方式
        modelAndView.setViewName("redirect:other.do");
        return modelAndView;
    }

    @RequestMapping("/other")
    public String other(String name, int age, Model model) {
        System.out.println("name=" + name + ",age=" + age);
        model.addAttribute("address", "新的地址");
        //显示的指定为forward转发，视图解析器不会使用前缀、后缀拼接视图
        return "forward:/redirect.jsp";
    }
}
